//
//  StatusCell.swift
//  sinaWeibo
//
//  Created by 张国梁 on 16/4/13.
//  Copyright © 2016年 CoderGL. All rights reserved.
//

import UIKit
import SnapKit

enum StatusCellIdentifier: String {
    case OriginalCell = "OriginalCell"
    case RetweetCell = "RetweetCell"
    
    // 枚举中static func 相当于 一个类中的类方法
    // .rawValue 是枚举的 默认值
    static func cellID(status: Status) -> String {
        return status.retweeted_status == nil ? OriginalCell.rawValue : RetweetCell.rawValue
    }
    
}

class StatusCell: UITableViewCell {
    /// 微博数据
    var status: Status?{
        didSet{
            topView.status = status
            
            contentLabel.text = status?.text
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.addSubview(topView)
        contentView.addSubview(contentLabel)
        contentView.addSubview(pictureView)
        contentView.addSubview(toolBar)
        
        
        
        // 布局子控件
        topView.snp_updateConstraints { (make) in
            make.top.left.right.equalTo(contentView)
            make.height.equalTo(margin + iconH + margin)
        }
    
        contentLabel.snp_updateConstraints { (make) in
            make.left.equalTo(contentView).offset(margin)
            make.top.equalTo(topView.snp_bottom)
            make.width.equalTo(width)
        }
        
        
    }
    
    func cellHeight(status: Status) -> CGFloat {
        self.status = status
        
        self.layoutIfNeeded()
        
        print("-------------------------------")
        return CGRectGetMaxY(toolBar.frame)
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var pictureViewW: NSLayoutConstraint?
    var pictureViewH: NSLayoutConstraint?
    var pictureViewT: NSLayoutConstraint?
    
    private lazy var topView: StatusTopView = StatusTopView()

    lazy var contentLabel: UILabel = {
       let label = UILabel.label(UIColor.blackColor(), fontSize: 14)
        label.numberOfLines = 0
        label.preferredMaxLayoutWidth = width
        return label
    }()
    
    lazy var toolBar: StatusBottomView = StatusBottomView()
    
    lazy var pictureView: StatusPictureView = StatusPictureView()
}

